﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace BHair.Base
{
    public partial class frmspfl : Form
    {
        public frmspfl()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void button1_Click(object sender, EventArgs e)
        {
            //判断是修改还是新增
            if (chuanzhi.flup == 0)
            {
                if (textBox2.Text != string.Empty)
                {
                    string sql = string.Format("INSERT INTO [商品分类]([type]) VALUES ('{0}')", textBox2.Text.ToString());
                    SqlConnection conn = new SqlConnection(constr);
                    try
                    {
                        conn.Open();
                        SqlCommand comm = new SqlCommand(sql, conn);
                        comm.ExecuteNonQuery();
                        MessageBox.Show("添加成功");
                        this.textBox2.Text = null;
                        conn.Close();
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("请填写分类名称！");
                }
            }
            else
            {
                //修改
                SqlConnection conn = new SqlConnection(constr);
                conn.Open();
                string sqlstr =string.Format( "UPDATE [商品分类] SET [type] = '{0}' WHERE ID={1}",textBox2.Text,chuanzhi.flid);
                SqlCommand comm = new SqlCommand(sqlstr,conn);
                comm.ExecuteNonQuery();
                MessageBox.Show("修改成功");
                this.Close();
            }
        }

        private void frmspfl_Load(object sender, EventArgs e)
        {
            //判断是否是修改
            if (chuanzhi.flup == 0)
            {
            }
            else if(chuanzhi.flup==1)
            {
                //修改
                textBox2.Text = chuanzhi.flname.Trim();

            }
        }
    }
}
